<?php
class File_Manager_Model extends CI_Model
{
    function __construct() {
        parent::__construct();
    }
	function get_all_file($num,$offset,$arr_search,$arr_search=array())
	{
        /*Begin search*/
        if($arr_search){
            switch($arr_search['field_search'])
            {
                case 'TT':
                    $this->db->like('title',$arr_search['key_search']);
                    break ;
                case 'DEC':
                    $this->db->like('description',$arr_search['key_search']);
                    break ;
            }
        }
		/*End search*/
		 $this->db->order_by('file_image_id','DESC');
		 $query = $this->db->get('file_image',$num,$offset);
		 return $query->result();
	}
	function get_num_file($arr_search,$arr_search=array())
	{
        /*Begin search*/
        if($arr_search){
            switch($arr_search['field_search'])
            {
                case 'TT':
                    $this->db->like('title',$arr_search['key_search']);
                    break ;
                case 'DEC':
                    $this->db->like('description',$arr_search['key_search']);
                    break ;
            }
        }
		/*End search*/
		 $query = $this->db->get('file_image');
		 return $query->num_rows();
	} 
    function saveData($file_image_id,$data){
        if($file_image_id!=0){
            $this->db->where('file_image_id',$file_image_id);
            if($this->db->update('file_image',$data)){
                 return true;
            }else{
                 return false;
            }
        }else{
            if($this->db->insert('file_image',$data)){
                return true;

            }else{
                return false;
            }
        }
    }
    /**Hieu vo**/
    function get_all_file_dir($dir,$num,$offset,$arr_search=array())
	{
        /*Begin search*/
        if($arr_search)
        {
            switch($arr_search['field_search'])
            {
                case 'TT':
                    $this->db->like('lb_title',$arr_search['key_search']);
                    break ;
                case 'DEC':
                    $this->db->like('description',$arr_search['key_search']);
                    break ;
            }
        }
		/*End search*/
        
         $this->db->where('lb_dir',$dir);
		 $this->db->order_by('file_data_id','DESC');
         
		 $query = $this->db->get('sys_file_data',$num,$offset);
		 //echo $this->db->last_query();
         return $query->result();
	}
	function get_num_file_dir($dir,$arr_search=array())
	{
        /*Begin search*/
        if($arr_search){
            switch($arr_search['field_search'])
            {
                case 'TT':
                    $this->db->like('lb_title',$arr_search['key_search']);
                    break ;
                case 'DEC':
                    $this->db->like('description',$arr_search['key_search']);
                    break ;
            }
        }
		/*End search*/
         $this->db->where('lb_dir',$dir);
		 $query = $this->db->get('sys_file_data');
		 return $query->num_rows();
	}
    function insert_file($data)
	{
            if($this->db->insert('sys_file_data',$data))
                return true;
            else
                return false;
	}
    function getAllImageCat(){
       $query = $this->db->get('file_image_cat');
       return $query->result();
    }
}
?>
